//
//  LRVisitorTableVC.swift
//  WeiboX
//
//  Created by admin on 01/12/2016.
//  Copyright © 2016 iOS_Objective-C. All rights reserved.
//

import UIKit

class LRVisitorTableVC: UITableViewController {

	var isLogin = LRUserAccountVM.sharedUserAccount.isLogin
	var visitorV: LRVisitorView?
	
	override func loadView() {
		if isLogin {
			super.loadView()
		} else {
			visitorV = LRVisitorView()
			visitorV?.backgroundColor = UIColor(white: 237 / 255, alpha: 1)
			
			visitorV?.delegate = self
			visitorV?.callBack = { 
//				print("我是闭包回调过来的")
				self.loadOauthVC()
			}
			setupNavUI()
			view = visitorV
		}
	}
	
	private func loadOauthVC() {
		let accountVC: LROAuthVC = LROAuthVC()
		let navVC: LRNavController = LRNavController(rootViewController: accountVC)
		present(navVC, animated: true, completion: nil)
	}
	
	private func setupNavUI() {
		navigationItem.leftBarButtonItem = UIBarButtonItem(title: "register", target: self, action: #selector(registerBtnAction))
		navigationItem.rightBarButtonItem = UIBarButtonItem(title: "login", target: self, action: #selector(loginBtnAction))
	}
	
	@objc private func registerBtnAction() {
//		print("注册")
		loadOauthVC()
	}
	
	@objc private func loginBtnAction() {
//		print("登录")
		loadOauthVC()
	}
	
	override func viewDidLoad() {
		super.viewDidLoad()
		
//		self.automaticallyAdjustsScrollViewInsets = true
    }
}

extension LRVisitorTableVC: LRVisitorViewDelegate {
	internal func accountBtnDidSelected() {
		print("我是代理方法传递过来的")
	}
}
